package com.example.controller;

import com.example.mall.Order;
import com.example.mall.Product;
import com.example.util.MockData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/selectOrderById/{orderNo}")
    public Order selectOrderById(@PathVariable("orderNo") String orderNo) {
        Order order = MockData.getOrder(orderNo);

        String url = "http://product-center/" + "selectProductByNo/" + order.getProductNo();

        Product product = restTemplate.getForObject(url, Product.class);

        order.setProductName(product.getProductName());

        return order;
    }
}
